home *** CD-ROM | disk | FTP | other *** search
/ QuickTime for the Web (2nd Edition) / QuickTime for the Web (2nd Edition).iso / pc / Demos / Mac / Matthew's Behaviors / Matthew'sMotionƒ / flipbounce < prev    next >
Encoding:
INI File  |  2001-09-10  |  2.9 KB  |  75 lines

  1. [Name]
  2. FlibBonce - From Matthew's Motion Suite.
  3. By Matthew Peterson, matthew@pinoko.berkeley.edu
  4.  
  5. [Description]
  6. 2-19-2000
  7. Drop this on a sprite, and it will flip back and fourth against the
  8. edges of the sprite track.
  9.  
  10. [Parameters]
  11.  
  12. [Frame loaded]
  13. Spritevars  MP_flipangle MP_flipheight MP_flipanglestep MP_boxheight MP_scx MP_scy
  14.  
  15. MP_flipanglestep = -180/17 //Use a divisor of 180, but not 90.
  16. // if we rotate by 90, we won't be able to see the sprite because
  17. //it is being viewed along the edge.
  18. MP_scx = spriteofid($thisspriteid).secondcornerx //Setup the edge of the sprite
  19. MP_scy = spriteofid($thisspriteid).secondcornery
  20. //remember how tall the sprite is:
  21. MP_boxheight = spriteofid($thisspriteid).boundsbottom - spriteofid($thisspriteid).boundstop
  22.  
  23. [Idle]
  24. SpriteVars MP_flipangle flipheight MP_flipanglestep MP_boxheight MP_scx MP_scy
  25. //XY FlipBounce By Matthew Peterson
  26. // This behavior gives the illusion of 3D by
  27. // flipping the sprite along its edge. It flips
  28. // over and over in one direction, then hits
  29. // the border of the track and returns in the
  30. // other direction.  Perspective is calculated
  31. // which is unusual since it requires sine and
  32. // cosine. This is calculated by rotating the
  33. // sprite and taking the ratio of hight and
  34. // width. It is a subtle and fast calcuation.
  35. MP_flipangle = MP_flipangle + MP_flipanglestep
  36. IF(MP_flipangle <= 0)// Stay within 360 degrees.
  37.     MP_flipangle = MP_flipangle + 360
  38.     MP_scx = FirstCornerX
  39.     MP_scy = FirstCornerY
  40. ENDIF
  41. ResetMatrix
  42.  
  43. Rotate(MP_flipangle)//Rotate in order to make trig calculations:
  44. flipheight = (ABS((SecondCornerY - FirstCornerY) * 0.3))
  45. IF(MP_flipangle < 180)
  46.     //roll against one edge
  47.     Stretch(FirstCornerX,SecondCornerY - flipheight,SecondCornerX, SecondCornerY, SecondCornerX,SecondCornerY + MP_boxheight,FirstCornerX,SecondCornerY + MP_boxheight + flipheight)
  48.     MoveBy(MP_scx- SecondCornerX,MP_scy - SecondCornerY)
  49. ELSEIF(MP_flipangle > 179 AND MP_flipangle < 181)
  50.     //Change the edge
  51.     Stretch(FirstCornerX,SecondCornerY,SecondCornerX, SecondCornerY, SecondCornerX,SecondCornerY + MP_boxheight,FirstCornerX,SecondCornerY + MP_boxheight)
  52.     IF(MP_flipanglestep > 0)
  53.         MoveBy(MP_scx- SecondCornerX,MP_scy - SecondCornerY)
  54.         MP_scx = FirstCornerX
  55.         MP_scy = FirstCornerY
  56.     ELSE
  57.         MoveBy(MP_scx- FirstCornerX,MP_scy - FirstCornerY)
  58.         MP_scx = SecondCornerX
  59.         MP_scy = SecondCornerY
  60.     ENDIF
  61. ELSEIF(MP_flipangle < 360)//agains the other edge
  62.     Stretch(FirstCornerX,FirstCornerY, SecondCornerX,FirstCornerY - flipheight,SecondCornerX, FirstCornerY+MP_boxheight + flipheight,FirstCornerX,FirstCornerY + MP_boxheight)
  63.     MoveBy(MP_scx- FirstCornerX,MP_scy - FirstCornerY)
  64. ELSEIF(MP_flipangle > 359)//change edge again
  65.     ResetMatrix
  66.     MoveBy(MP_scx- FirstCornerX,MP_scy - FirstCornerY)
  67.     MP_scx = SecondCornerX
  68.     MP_scy = SecondCornerY
  69.     MP_flipangle = 0
  70. ENDIF
  71. //See if it hits the edge of the sprite track, if so, 
  72. //change the direction.
  73. if(boundsleft < 0 or boundsright > trackwidth)
  74.     MP_flipanglestep = -MP_flipanglestep 
  75. endif